package indi.jp.project.process.controller;

import indi.jp.project.core.entity.JsonResult;
import indi.jp.project.process.entity.FlowTaskParam;
import indi.jp.project.process.service.FlowTaskService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.validation.Valid;

/**
 * 任务流程Controller
 *
 * @author jiangping
 * @date 2022/5/5
 */
@RestController
@RequestMapping("/flow/task")
public class FlowTaskController {

    @Resource
    private FlowTaskService flowTaskService;

    @GetMapping("/queryTaskFlow")
    public JsonResult queryTaskFlow(HttpServletRequest request) throws Exception {
        String taskId = request.getParameter("taskId");
        return flowTaskService.queryTaskFlow(taskId);
    }

    @PostMapping("/submit")
    public JsonResult flowSubmit(@RequestBody @Valid FlowTaskParam flowTaskParam, HttpServletRequest request) throws Exception {
        String createBy = request.getParameter("account");
        flowTaskParam.setCreateBy(createBy);
        return flowTaskService.flowSubmit(flowTaskParam);
    }

    @PostMapping("/reject")
    public JsonResult flowReject(@RequestBody @Valid FlowTaskParam flowTaskParam, HttpServletRequest request) throws Exception {
        String createBy = request.getParameter("account");
        flowTaskParam.setCreateBy(createBy);
        return flowTaskService.flowReject(flowTaskParam);
    }

    @PostMapping("/revoke")
    public JsonResult flowRevoke(@RequestBody @Valid FlowTaskParam flowTaskParam, HttpServletRequest request) throws Exception {
        String createBy = request.getParameter("account");
        flowTaskParam.setCreateBy(createBy);
        return flowTaskService.flowRevoke(flowTaskParam);
    }

    @GetMapping("/loadFlowHistory")
    public JsonResult loadFlowHistory(@RequestParam String taskId) throws Exception {
        return flowTaskService.loadFlowHistory(taskId);
    }

}
